package service.serviceImpl;

import dao.DepartInfoDao;
import dao.TeaDao;
import dao.daoImpl.DepartInfoDaoImpl;
import dao.daoImpl.TeaDaoImpl;
import pojo.Student;
import pojo.Teacher;
import service.StuService;
import service.TeaService;

import java.sql.SQLException;
import java.util.List;

public class TeaServiceImpl implements TeaService {

    TeaDao teaDao = new TeaDaoImpl();
    StuService stuService = new StuServiceImpl();
    DepartInfoDao departInfoDao = new DepartInfoDaoImpl();

    @Override
    public Teacher findTeaById(String id) throws SQLException {

        //调用dao查找教师管理的学生集合
        List<Student> list = teaDao.findStusById(id);
        //将集合中学生的部门信息(DepartInfo的id)改为改为真正的部门信息
        for (Student stu:list) {
            stuService.changeStuStatus(stu,departInfoDao);
        }

        Teacher tea = teaDao.findTeaById(id);
        if (list.size() == 0) {
            return tea;
        }
        for (Student stu:list) {
            tea.getTeaLists().add(stu);
        }
        return  tea;
    }
}
